﻿

#region Usings

using PolyGameEngine.GamePieces.Common;
using PolyGameEngine.Tools;

using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

#endregion

namespace PolyMorph.CustomGamePieces
{
    public class Oil : SensorForceTile
    {
        public Oil(PhysicsGame PhysicsGame, World World, Material Material,
            Texture2D SpriteSheet, Vector2 Position, int saveLineIndex)
            : base(PhysicsGame, World, Material, SpriteSheet, 1, Position, 0, 1, 1, saveLineIndex, "Oil", 8)
        { }

        int lightRes = 150;
        int heavyRes = 25;
        float resistance = 0;

        public override void Effect()
        {

            if (GamePieceInEffect.material.Identifier.Equals("Plastic"))
                resistance = GamePieceInEffect.Velocity.Y / heavyRes;
            else
                resistance = GamePieceInEffect.Velocity.Y / lightRes;

            if (resistance < 0)
                resistance = 0;

            if (!GamePieceInEffect.material.Identifier.Equals("Steel"))
            {
                bodyInEffect.ApplyForce(new Vector2(0, -5f - resistance));
            }

        }

        public override void StartEffect()
        {
            AffectedGamePiece.friction = 0;
            base.StartEffect();
        }

        public override void DuringEffect()
        {
            base.DuringEffect();
        }

        public override void EndEffect()
        {
            if (AffectedGamePiece != null)
            {
                AffectedGamePiece.friction = AffectedGamePiece.material.Friction;
            }
            base.EndEffect();
        }

        public override bool HandleDefaultCollision(Fixture ThisFixture, Fixture OtherFixture, Contact Contact)
        {
            return false;
        }

    }
}

